const pageConf = {
    extends: extendsQ,
    data() {
        return {
            // tab 切换值
            tabActiveName: "djjl",
            // tab 列表
            tabList: [
                { label: '待检记录', name: 'djjl' },
                { label: '已检记录', name: 'yjjl' }
            ],


            // 检测页传数据
            dataOptions: {},


            // 已检记录状态列表
            testStateOptions: [
                { label: "已检测", value: 3 },
                { label: "已发布", value: 5 },
                { label: "已撤回", value: 6 }
            ],
            // 已检记录表格数据
            testTableData: [],
            // 已检记录分页
            pagination: {
                currentPage: "1",
                pageSizes: [20, 40, 60],
                pageSize: "20",
                total: 0
            },
            // 表格加载动画
            tableLoading: false,
            // 是否显示检测页
            showTestPage: false,
            // 检测页传参
            dialogSource: 1,
            // 开始检测所属稻种列表
            seedRiceList: []
        }
    },
    computed: {

    },
    methods: {
        /**
         * tab 切换
         */
        handleTabClick() {

        },
        /**
         * 修改状态方法  
         * @param { Number } status  要修改的状态
         * @param { Number } id  要修改的列表
         * @param { * } reason  原因
         * @param { * } info    弹框信息
         * @param { Function } callback   回调
         * status:2-已接收、3-已检测、4-不予检测、5-已发布、6-已撤回发布、7-用户撤销申请,=4时传reason
         */
        modifyStatus(status, id, reason = "", info, callback) {
            let params = { "id": id, "status": status, "reason": reason, current_user_id: GLOBAL_CONFIG.userId() }
            tpHttp.post(this, "action=com.top.riceInstitute.QualityRiceEvaluateInfo.editStatus", { param: JSON.stringify(params) }, (data, code, message) => {
                if (code == 0) {
                    let message = (info || "修改状态") + "成功"
                    this.$message.success(message)
                    callback()
                } else {
                    let ermessage = (info || "修改状态") + "失败"
                    this.$message.error(ermessage)
                }
            })
        },
        /**
         * 获取已检记录表格数据
         */
        getTableDataList() {
            this.tableLoading = true
            let params = { "page": this.pagination.currentPage, "size": this.pagination.pageSize, "status": "3,5,6", "user_id": GLOBAL_CONFIG.userId(), "apply_number": "" }
            tpHttp.post(this, "action=com.top.riceInstitute.QualityRiceEvaluateInfo.search", { param: JSON.stringify(params) }, (data, code, message) => {
                if (code == 0 && data?.list?.length) {
                    this.testTableData = data.list;
                    this.pagination.total = Number(data.total) || 0;
                } else {
                    this.testTableData = []
                }
                this.tableLoading = false
            })
        },
        /**
         * 已检记录发布点击
         */
        testReleaseClick(item) {
            this.$confirm('发布后送检人员将在“知稻”上收到您的检测结果提醒并查看', '您确定要发布吗？', {
                confirmButtonText: '确定发布',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.modifyStatus(5, item.id, "", "发布", this.getTableDataList)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消发布'
                });
            });
        },
        /**
         * 已检记录撤回点击
         * @param {*} item 当列数据 
         */
        testWithdrawClick(item) {
            this.$confirm('撤回后送检人员将在“知稻”已检记录上看不到检测结果', '您确定要撤回吗？', {
                confirmButtonText: '确定撤回',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.modifyStatus(6, item.id, "", "撤回", this.getTableDataList)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消撤回'
                });
            });
        },
        /**
         * 获取已检记录详情
         * @param {*} id 记录 id 
         */
        getTestDetail(id) {
            let params = { "id": id }
            return new Promise((resolve, reject) => {
                tpHttp.post(this, "action=com.top.riceInstitute.QualityRiceEvaluateInfo.get", { param: JSON.stringify(params) }, (data, code, message) => {
                    if (code == 0 && data && JSON.stringify(data) != "{}") {
                        resolve(data)
                    } else {
                        reject()
                    }
                })
            })
        },
        /**
         * 已检记录重检点击
         */
        recheckClick(item) {
            this.dialogSource = 3;
            this.getTestDetail(item.id).then(res => {
                this.showTestPage = true;
                this.dataOptions = {};
                this.$nextTick(() => {
                    this.dataOptions = res
                })
            }).catch(err => {
                this.$message.error("重检失败，请稍后重试！")
            })
            
        },
        /**
         * 已检记录删除点击
         */
        testDelClick(item) {
            this.$confirm('您确定要删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = { "id": item.id }
                tpHttp.post(this, "action=com.top.riceInstitute.QualityRiceEvaluateInfo.del", { param: JSON.stringify(params) }, (data, code, message) => {
                    if (code == 0) {
                        this.$message.success("删除成功")
                        this.getTableDataList();
                    } else {
                        this.$message.error("删除失败")
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        /**
         * 已检记录导出点击
         */
        testExportClick() {

            let href = GLOBAL_CONFIG.getVirtualPath() + "/api_server/export/riceEvaluateExport?status=3,5,6"
            const a = document.createElement("a")
            a.setAttribute("download", "已检记录")
            a.setAttribute("href", href)
            a.click();
            // window.open(href)
        },
        /**
         * 已检记录分页每页条数切换
         * @param { Number } val 
         */
        handleSizeChange(val) {
            this.pagination.pageSize = val;
            this.getTableDataList();
        },
        /**
         * 已检记录分页页数切换
         * @param { Number } val 
         */
        handleCurrentChange(val) {
            this.pagination.currentPage = val;
            this.getTableDataList();
        },

        /**
         * 开始检测页面返回点击
         */
        testBackClick() {
            this.showTestPage = false;
        },
        
        /**
         * 开始检测页面 评价弹框确认点击
         */
        testResultDefinHandle() {
            this.showTestPage = false;
            this.getTableDataList();
        }
    },
    mounted() {
        // 获取已检记录表格数据
        this.getTableDataList();
    }
}